//
//  LKDailyChartTeamChooseViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/8/15.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKDailyChartTeamChooseViewController.h"
#import "LKDailyChartTeamChooseCell.h"
#import "LKDailyChartTeamChooseDetailViewController.h"
#import "LKDailyChartTeamViewController.h"
#import "LKDailyChartViewController.h"
#import "LKDailyChartListModel.h"
@interface LKDailyChartTeamChooseViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate>
@property(nonatomic,strong)LKBaseTableview *tableview;
@property(nonatomic,strong)NSMutableArray *datalistArray;

@end

@implementation LKDailyChartTeamChooseViewController

-(LKBaseTableview *)tableview{
    if (!_tableview) {
        _tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(12, NAVIGATION_BAR_HEIGHT + 12, WIDTH - 24, HEIGHT - NAVIGATION_BAR_HEIGHT - 12) style:UITableViewStylePlain registercellClasss:@[@"LKDailyChartTeamChooseCell"]];
        [self.view addSubview:_tableview];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSelectionStyleGray;
        _tableview.tableFooterView = [[UIView alloc] init];
        _tableview.backgroundColor = [UIColor whiteColor];
    }
    return _tableview;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableview.estimatedRowHeight = 200;
    self.departmentId = self.departmentId == nil ? @"0":self.departmentId;
    [self getEmployersOfTeamLeader];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBarTintColor:blueDefault];
    //设置导航条文字颜色 白色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.delegate = self;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
    //设置导航条文字颜色 白色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:COLOR_HEX(0x000000)}];
    
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"选择";
//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [btn setImage:[UIImage imageNamed:@"06"] forState:UIControlStateNormal];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
//    [btn addTarget:self action:@selector(rightQustionAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.backButton setImage:[UIImage imageNamed:@"back2"] forState:UIControlStateNormal];
    [self.backButton setTitle:@" 返回" forState:UIControlStateNormal];
    [self.backButton setTitleColor:[UIColor whiteColor]];
}

/**
 导航栏右侧的按钮点击响应
 */
-(void)rightQustionAction:(UIButton *)btn{
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.datalistArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKDailyChartTeamChooseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKDailyChartTeamChooseCell"];
    cell.model = self.datalistArray[indexPath.row];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftViewTap:)];
    cell.leftTapView.tag = 10000 + indexPath.row;
    [cell.leftTapView addGestureRecognizer:leftTapGes];
    UITapGestureRecognizer *rightTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightViewTap:)];
    [cell.rightTapView addGestureRecognizer:rightTapGes];
    cell.rightTapView.tag = 100000 + indexPath.row;
    return cell;
}

/**
 左侧视图点击直接查看详细信息

 @param tap 左侧点击手势
 */
-(void)leftViewTap:(UITapGestureRecognizer *)tap{
    UIView *view = tap.view;
    LKDailyChartListModel *model = self.datalistArray[view.tag - 10000];
    if (![model.isDepartment boolValue]) {
        LKDailyChartViewController *vc = [[LKDailyChartViewController alloc] init];
        vc.userId = model.departmentUserId;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        LKDailyChartTeamViewController *vc = [[LKDailyChartTeamViewController alloc] init];
        vc.departmentId = model.departmentUserId;
        vc.departmentName = model.departmentUserName;
        [self.navigationController pushViewController:vc animated:YES];
    }

}
/**
 右侧视图点击直接查看详细信息
 
 @param tap 右侧点击手势
 */
-(void)rightViewTap:(UITapGestureRecognizer *)tap{
    UIView *view = tap.view;
    LKDailyChartListModel *model = self.datalistArray[view.tag - 100000];
    LKDailyChartTeamChooseDetailViewController *vc = [[LKDailyChartTeamChooseDetailViewController alloc] init];
    vc.departmentId = model.departmentUserId;
    if (![model.isDepartment boolValue]) {
        return;
    }
    [self.navigationController pushViewController:vc animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

/**
 获取领导下属的列表信息
 */
-(void)getEmployersOfTeamLeader{
    NSDictionary *param = @{@"DepartmentId":self.departmentId};
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:teamLeaderGetEmployerUrl header:[LKUserInforTool header] parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        NSArray *arra = responseObject[@"result"];
        for (NSDictionary *dic in arra) {
            LKDailyChartListModel *model = [LKDailyChartListModel modelWithDictionary:dic];
            [self.datalistArray addObject:model];
        }
        [self.tableview reloadData];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
-(NSMutableArray *)datalistArray{
    if (!_datalistArray) {
        _datalistArray = [[NSMutableArray alloc] init];
    }
    return _datalistArray;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
